//
//  CountDownWidget.swift
//  memoWidgetExtension
//
//  Created by DaleGuo on 2023/10/18.
//

import Foundation

//
//  memoWidget.swift
//  memoWidget
//
//  Created by DaleGuo on 2023/10/8.
//

import ActivityKit
import SwiftUI
import WidgetKit

struct ActiveCountDownView: View {
    let context: ActivityViewContext<CountDonwAttributes>

    var body: some View {
        VStack {
            Text(context.attributes.timerName)
                .font(.headline)

            Text(context.state.endTime, style: .timer) // 使用timer有倒计时效果
        }
        .padding()
    }
}

struct ActiveCountDownWidget: Widget {
    let kind: String = "countDownWidget"

    var body: some WidgetConfiguration {
        ActivityConfiguration(for: CountDonwAttributes.self) { context in
            ActiveCountDownView(context: context)
        } dynamicIsland: { _ in
            // 暂时不用灵动岛
            DynamicIsland {
                DynamicIslandExpandedRegion(.leading) {
                    Label("Coundown", systemImage: "bag")
                        .foregroundColor(.indigo)
                        .font(.title2)
                }
            } compactLeading: {} compactTrailing: {} minimal: {}
        }
        
    }
}


